package com.mjlf.proxy.cglib;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;

/**
 * @ClassName Test
 * @auther mjlf
 * @Date 2019/9/18 18:15
 * @Description 测试类
 */
public class Test {

    public static void main(String[] args) {
        // 代理类class文件存入本地磁盘方便我们反编译查看源码
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "code");
        // 通过CGLIB动态代理获取代理对象的过程
        Enhancer enhancer = new Enhancer();
        //设置目标对象父类
        enhancer.setSuperclass(Go.class);
        //设置回调方法
        enhancer.setCallback(new MyMethodInterceptor());
        //生成代理对象
        Go go = (Go)enhancer.create();
        go.go();
    }
}
